$(function  () {
    //获取菜单
    $.post(
        ipurl+'/user/get',
        function(result) {
            if(result.code == 200){
                var userlist = result.data.results;
                var userhtml = '';
                for(var i=0;i<userlist.length;i++){
                    userhtml+='<tr>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].ID;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].COLLEAGE;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].XNUM;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].USERNAME;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].PASSWORD;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].ADDTIME;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].EDITTIME;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    if(userlist[i].TYPE==1){
                        userhtml+='学生';
                    }else if(userlist[i].TYPE==2){
                        userhtml+='老师';
                    }else{
                        userhtml+=userlist[i].TYPE;
                    }
                    userhtml+='</td>';
                    userhtml+='<td class="td-manage">';
                    userhtml+='<a title="编辑" href="javascript:;" onclick="user_edit('+"'"+'编辑'+"'"+','+"'"+'mauser-edit.html'+"'"+','+"'"+userlist[i].ID+"'"+','+"'"+userlist[i].COLLEAGE+"'"+','+"'"+userlist[i].XNUM+"'"+','+"'"+userlist[i].USERNAME+"'"+','+"'"+userlist[i].PASSWORD+"'"+','+'500'+','+'510'+')"  class="ml-5" style="text-decoration:none">';
                    userhtml+='<i class="layui-icon">&#xe642;</i>';
                    userhtml+='</a>';
                    userhtml+='<a title="删除" href="javascript:;" onclick="user_del(this,'+userlist[i].ID+')"  style="text-decoration:none">';
                    userhtml+='<i class="layui-icon">&#xe640;</i>';
                    userhtml+='</a>';
                    userhtml+='</td>';
                    userhtml+='</tr>';
                }
                $("#menubody").html(userhtml);
            }
        }
    );
})

function menugo(address){
    $("#rightcontent").attr('src',address);
}


function user_add(title,url,w,h){
    x_admin_show(title,url,w,h);
}
// 用户-编辑
function user_edit (title,url,id,colleage,xnum,username,pwd,w,h) {
    $.cookie("uid", id, { expires: 1 });
    $.cookie("ucolleage", colleage, { expires: 1 });
    $.cookie("uxnum", xnum, { expires: 1 });
    $.cookie("uname", username, { expires: 1 });
    $.cookie("upwd", pwd, { expires: 1 });
    x_admin_show(title,url,w,h); 
}
/*菜单-删除*/
function user_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
        //发异步删除数据
        $(obj).parents("tr").remove();
        layer.msg('已删除!',{icon:1,time:1000});
        $.post(
            ipurl+'/user/del',
            {
              ID: id
            },
            function(result) {
              console.log(result);
                // layer.open({
                //     content: '添加成功',
                //     end: function(index, layero){
                     
                //     }
                // });
            }
      );
    });
}
